import router from "./router";
import { getToken } from "./utils/auth";
import NProgress from "nprogress"; // 引入一份进度条插件
import "nprogress/nprogress.css"; // 引入进度条样式
import store from "./store";
router.beforeEach(async (to, from, next) => {
  NProgress.start();
  const token = getToken();
  const whiteList = ["/login", "/404"];
  if (token) {
    if (to.path === "/login") {
      next("/");
    } else {
      // if (!store.getters.userId) {
      //   // let { roles } = await store.dispatch("user/getUserProfileAction");
      //   next(to.path);
      // } else {
      //   next();
      // }
      next();
    }
  } else {
    if (whiteList.includes(to.path)) {
      next();
    } else {
      next("/login");
    }
  }
  NProgress.done();
});
router.afterEach(() => {
  NProgress.done();
});
